﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections;

namespace SpaceRivals
{
      
    public class cGeneric
    {
        /// <summary>
        /// Méthode retournant le prochain ID disponible selon la table demandée
        /// </summary>
        /// <param name="unType"></param>
        /// <returns></returns>
        
        public string GenererId(Type unType)
        {
            DBSpaceRivalsDataContext DB = new DBSpaceRivalsDataContext();
            string valeurRetour = "";
            string DernierID = "";

            if (unType.Equals(typeof(TJOUEUR)))
                DernierID = (from classe in DB.TJOUEUR select classe.IDJOUEUR).Max();
            else if (unType.Equals(typeof(TINFOSCONNEXION)))
                DernierID = (from classe in DB.TINFOSCONNEXION select classe.IDINFOSCONNEXION).Max();
            else if (unType.Equals(typeof(TLOCALISATIONSIP)))
                DernierID = (from classe in DB.TLOCALISATIONSIP select classe.IDLOCALISATIONIP).Max();
            else if (unType.Equals(typeof(TSOCIETE_D_INVESTISSEMENT)))
                DernierID = (from classe in DB.TSOCIETE_D_INVESTISSEMENT select classe.IDSOCIETE).Max();
            else if (unType.Equals(typeof(TSPECIALISATIONBANQUE)))
                DernierID = (from classe in DB.TSPECIALISATIONBANQUE select classe.IDSPECIALISATIONBANQUE).Max();
            else if (unType.Equals(typeof(TSPECIALISATIONSOCIETE)))
                DernierID = (from classe in DB.TSPECIALISATIONSOCIETE select classe.IDSPECIALISATIONSOCIETE).Max();
            else if (unType.Equals(typeof(TMODIFICATEURSSOCIETE)))
                DernierID = (from classe in DB.TMODIFICATEURSSOCIETE select classe.IDMODIFICATEURSOCIETE).Max();
            else if (unType.Equals(typeof(TMODIFICATEURSBANQUE)))
                DernierID = (from classe in DB.TMODIFICATEURSBANQUE select classe.IDMODIFICATEURBANQUE).Max();
            else if (unType.Equals(typeof(TFINANCEMENT)))
                DernierID = (from classe in DB.TFINANCEMENT select classe.IDFINANCEMENT2).Max();
            else if (unType.Equals(typeof(TPERSO)))
                DernierID = (from classe in DB.TPERSO select classe.IDMESSAGE).Max();

            if (DernierID != "") valeurRetour = Convert.ToString(Convert.ToInt64(DernierID) + 1);
            else valeurRetour = "1";

            return valeurRetour;
        }
    }
}
